#include<bits/stdc++.h>

using namespace std;
using ll = long long;
#define endl '\n'


ll sum1(ll p, ll q) {//O(n)
    ll s = 0;
    for (ll i = p; i <= q; i++) {
        s += i;
    }
    return s;

}

ll sum2(ll p, ll q) {//O(1)
    ll s = (q - p + 1) * (p + q) >> 1;
    return s;

}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    // 测试数据
    int test_cases[] = {10, 100, 1000, 10000, 100000, 1000000, 10000000};
    for (int t:test_cases) {
        // 记录开始时间
        auto start = chrono::steady_clock::now();

        sum2(1, t);
        // 记录结束时间
        auto end = chrono::steady_clock::now();

        // 输出程序运行结果和时间
        cout << "T(" << t << ") = " << chrono::duration<double, milli>(end - start).count() << " ms" << endl;
    }

    return 0;
}